home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / ip / nfs / nfstrace.shar.Z / nfstrace.shar / xdr_nfs.c < prev   
Encoding:
C/C++ Source or Header  |  1992-02-06  |  5.4 KB  |  252 lines

  1. /* NFS XDR decoding functions
  2.  * Matt Blaze
  3.  * Copyright 1991 Matt Blaze.
  4.  * May be freely reproduced for non-commerical use.
  5.  * All other rights, including use for direct commerical advantage or
  6.  * use in a commerical product, are reserved by the author. 
  7.  * 
  8.  *
  9.  * Note: these are not complete - just enough for rpcspy.
  10.  * In particular, a lot of the data pointers are never filled in,
  11.  * and many functions are decode-only.
  12.  * If you want to use this for a real nfs client or server, you'll need to
  13.  * change the readreply, writeargs, directory reply and statfs functions.
  14.  * If it's going to be in the kernel, you probably will need to change things
  15.  * to deal with mbufs as well.
  16.  * These functions are probably too slow for serious use.
  17.  */
  18.  
  19. #include <sys/types.h>
  20. #include <sys/time.h>
  21. #include <sys/errno.h>
  22. #include <rpc/types.h>
  23. #include <rpc/xdr.h>
  24. #include <nfs/nfs.h>
  25. #include <netinet/in.h>
  26.  
  27. bool_t xdr_fattr();
  28. bool_t xdr_drok ();
  29. bool_t xdr_srok ();
  30. bool_t xdr_rrok ();
  31.  
  32. struct xdr_discrim d_attrstat[2] = {
  33.     {NFS_OK, xdr_fattr},{__dontcare__, NULL}};
  34.  
  35. xdr_attrstat(xp, as)
  36.      XDR *xp;
  37.      struct nfsattrstat *as;
  38. {
  39.     return(xdr_union(xp, &as->ns_status, &as->ns_attr,
  40.              d_attrstat,NULL));
  41. }
  42.  
  43. xdr_creatargs(xp,ca)
  44.      XDR *xp;
  45.      struct nfscreatargs *ca;
  46. {
  47.     return(xdr_diropargs(xp, &ca->ca_da) &&
  48.            xdr_sattr(xp, &ca->ca_sa));
  49. }
  50.  
  51. xdr_diropargs(xp,da)
  52.      XDR *xp;
  53.      struct nfsdiropargs *da;
  54. {
  55.     return(xdr_fhandle(xp, &da->da_fhandle) &&
  56.            xdr_string(xp, &da->da_name,NFS_MAXNAMLEN));
  57. }
  58.  
  59. struct xdr_discrim d_diropres[2]={
  60.     {NFS_OK, xdr_drok},
  61.     {__dontcare__,NULL}};
  62.  
  63. xdr_diropres(xp,dr)
  64.      XDR *xp;
  65.      struct nfsdiropres *dr;
  66. {
  67.     return (xdr_union(xp,&dr->dr_status, &dr->dr_drok,
  68.               d_diropres, NULL));
  69. }
  70.  
  71. xdr_drok(xp,dok)
  72.      XDR *xp;
  73.      struct nfsdrok *dok;
  74. {
  75.     return(xdr_fhandle(xp,&dok->drok_fhandle) &&
  76.            xdr_fattr(xp,&dok->drok_attr));
  77. }
  78.  
  79. xdr_fattr(xp,fa)
  80.      XDR *xp;
  81.      struct nfsfattr *fa;
  82. {
  83.     return(xdr_enum(xp,&fa->na_type) &&
  84.            xdr_u_long(xp,&fa->na_mode)&&
  85.            xdr_u_long(xp,&fa->na_nlink)&&
  86.            xdr_u_long(xp,&fa->na_uid)&&
  87.            xdr_u_long(xp,&fa->na_gid)&&
  88.            xdr_u_long(xp,&fa->na_size)&&
  89.            xdr_u_long(xp,&fa->na_blocksize)&&
  90.            xdr_u_long(xp,&fa->na_rdev)&&
  91.            xdr_u_long(xp,&fa->na_blocks)&&
  92.            xdr_u_long(xp,&fa->na_fsid)&&
  93.            xdr_u_long(xp,&fa->na_nodeid)&&
  94.            xdr_timeval(xp,&fa->na_atime)&&
  95.            xdr_timeval(xp,&fa->na_mtime)&&
  96.            xdr_timeval(xp,&fa->na_ctime));
  97. }
  98.  
  99. xdr_fhandle(xp, fh)
  100.      XDR *xp;
  101.      fhandle_t *fh;
  102. {
  103.     return(xdr_opaque(xp,fh,NFS_FHSIZE));
  104. }
  105.  
  106. xdr_linkargs(xp, la)
  107.      XDR *xp;
  108.      struct nfslinkargs *la;
  109. {
  110.     return(xdr_fhandle(xp, &la->la_from) &&
  111.            xdr_diropargs(xp, &la->la_to));
  112. }
  113.  
  114. xdr_rddirargs(xp, ra)
  115.      XDR *xp;
  116.      struct nfsrddirargs *ra;
  117. {
  118.     return (xdr_fhandle(xp, &ra->rda_fh) &&
  119.         xdr_u_long(xp, &ra->rda_offset)&&
  120.         xdr_u_long(xp, &ra->rda_count));
  121. }
  122.  
  123. /* this is incomplete! just decodes the status. no put function, either */
  124. xdr_getrddirres(xp, rr)
  125.      XDR *xp;
  126.      struct nfsrddirres *rr;
  127. {
  128.     return(xdr_enum(xp, &rr->rd_status));
  129. }
  130.  
  131.  
  132. struct xdr_discrim d_rdlnres[2]={
  133.     {NFS_OK, xdr_srok},
  134.     {__dontcare__,NULL}};
  135.  
  136. xdr_rdlnres(xp, rr)
  137.      XDR *xp;
  138.      struct nfsrdlnres *rr;
  139. {
  140.     return (xdr_union(xp, &rr->rl_status, &rr->rl_srok,
  141.               d_rdlnres, NULL));
  142. }
  143.  
  144. struct xdr_discrim d_rdres[2]={
  145.     {NFS_OK, xdr_rrok},
  146.     {__dontcare__,NULL}};
  147.  
  148. xdr_rdresult(xp, rr)
  149.      XDR *xp;
  150.      struct nfsrdresult *rr;
  151. {
  152.     return(xdr_union(xp, &rr->rr_status, &rr->rr_ok,
  153.              d_rdres, NULL));
  154. }
  155.  
  156. xdr_readargs(xp, ra)
  157.      XDR *xp;
  158.      struct nfsreadargs *ra;
  159. {
  160.     return (xdr_fhandle(xp, &ra->ra_fhandle)&&
  161.         xdr_long(xp, &ra->ra_offset)&&
  162.         xdr_long(xp, &ra->ra_count)&&
  163.         xdr_long(xp, &ra->ra_totcount));
  164. }
  165.  
  166. xdr_rnmargs(xp, ra)
  167.      XDR *xp;
  168.      struct nfsrnmargs *ra;
  169. {
  170.     return (xdr_diropargs(xp, &ra->rna_from) &&
  171.         xdr_diropargs(xp, &ra->rna_to));
  172. }
  173.  
  174.  
  175.  
  176.  
  177. /* this isn't complete.  doesnt fill in the data field */
  178. xdr_rrok(xp, rok)
  179.      XDR *xp;
  180.      struct nfsrrok *rok;
  181. {
  182.     return (xdr_fattr(xp, &rok->rrok_attr) &&
  183.         xdr_int(xp, &rok->rrok_count));
  184.     /* should fill in count bytes of data to be complete */
  185. }
  186.  
  187. xdr_saargs(xp, sa)
  188.      XDR *xp;
  189.      struct nfssaargs *sa;
  190. {
  191.     return(xdr_fhandle(xp, &sa->saa_fh)&&
  192.            xdr_sattr(xp, &sa->saa_sa));
  193. }
  194.  
  195. xdr_sattr(xp, sa)
  196.      XDR *xp;
  197.      struct nfssattr *sa;
  198. {
  199.     return (xdr_u_long(xp, &sa->sa_mode)&&
  200.         xdr_u_long(xp, &sa->sa_uid)&&
  201.         xdr_u_long(xp, &sa->sa_gid)&&
  202.         xdr_u_long(xp, &sa->sa_size)&&
  203.         xdr_timeval(xp, &sa->sa_atime)&&
  204.         xdr_timeval(xp, &sa->sa_mtime));
  205. }
  206.  
  207. xdr_slargs(xp,sa)
  208.      XDR *xp;
  209.      struct nfsslargs *sa;
  210. {
  211.     return (xdr_diropargs(xp, &sa->sla_from)&&
  212.         xdr_string(xp, &sa->sla_tnm, NFS_MAXPATHLEN)&&
  213.         xdr_sattr(xp, &sa->sla_sa));
  214. }
  215.  
  216. xdr_srok(xp, sr)
  217.      XDR *xp;
  218.      struct nfssrok *sr;
  219. {
  220.     return (xdr_bytes(xp, &sr->srok_data,
  221.               &sr->srok_count, NFS_MAXPATHLEN));
  222. }
  223.  
  224. xdr_timeval(xp, tv)
  225.      XDR *xp;
  226.      struct timeval *tv;
  227. {
  228.     return (xdr_long(xp, &tv->tv_sec)&&
  229.         xdr_long(xp, &tv->tv_usec));
  230. }
  231.  
  232. /* this is incomplete! does not fill in data field */
  233. xdr_writeargs(xp, wa)
  234.      XDR *xp;
  235.      struct nfswriteargs *wa;
  236. {
  237.     return(xdr_fhandle(xp, &wa->wa_fhandle)&&
  238.            xdr_long(xp, &wa->wa_begoff)&&
  239.            xdr_long(xp, &wa->wa_offset)&&
  240.            xdr_long(xp, &wa->wa_totcount)&&
  241.            xdr_long(xp, &wa->wa_count));     /* should be xdr_bytes */
  242. }
  243.  
  244.  
  245. /* this is incomplete! just checks the return status */
  246. xdr_statfs(xp, fs)
  247.      XDR *xp;
  248.      struct nfsstatfs *fs;
  249. {
  250.     return(xdr_enum(xp, &fs->fs_status));
  251. }
  252.